Exploratory Data Analysis

df_resources_prices

# Read csv file
df_resources <- read.csv("../../data/01-modified-data/clean_resources-price.csv")

names(df_resources) <- c("DATE", "Uranium", "Natural Gas")

df_resources$DATE <- as.Date(df_resources$DATE)
df_resources <- pivot_longer(df_resources, 
                        cols = -DATE,  # Replace 'ID' with the name of your ID column
                        names_to = "Resources",  # Name for the new variable column
                        values_to = "Prices")    # Name for the new value column

df_resources
A tibble: 264 × 3
DATE Resources Prices
<date> <chr> <dbl>
2012-01-01 Uranium 52.31250
2012-01-01 Natural Gas 3.25400
2012-02-01 Uranium 52.05556
2012-02-01 Natural Gas 3.43600
2012-03-01 Uranium 51.28889
2012-03-01 Natural Gas 3.71700
2012-04-01 Uranium 51.30000
2012-04-01 Natural Gas 3.87400
2012-05-01 Uranium 51.88889
2012-05-01 Natural Gas 3.71800
2012-06-01 Uranium 50.83333
2012-06-01 Natural Gas 3.51800
2012-07-01 Uranium 50.35556
2012-07-01 Natural Gas 3.29100
2012-08-01 Uranium 49.25000
2012-08-01 Natural Gas 3.60600
2012-09-01 Uranium 47.72500
2012-09-01 Natural Gas 3.79700
2012-10-01 Uranium 44.61111
2012-10-01 Natural Gas 3.75000
2012-11-01 Uranium 41.50000
2012-11-01 Natural Gas 3.40600
2012-12-01 Uranium 43.66667
2012-12-01 Natural Gas 3.33700
2013-01-01 Uranium 42.75000
2013-01-01 Natural Gas 3.23300
2013-02-01 Uranium 43.40625
2013-02-01 Natural Gas 3.47100
2013-03-01 Uranium 42.28125
2013-03-01 Natural Gas 3.69800
... ... ...
2021-10-01 Uranium 38.47619
2021-10-01 Natural Gas 3.09300
2021-11-01 Uranium 31.09958
2021-11-01 Natural Gas 3.28000
2021-12-01 Uranium 36.12930
2021-12-01 Natural Gas 3.20400
2022-01-01 Uranium 36.87292
2022-01-01 Natural Gas 3.14100
2022-02-01 Uranium 35.83191
2022-02-01 Natural Gas 3.33000
2022-03-01 Uranium 45.51470
2022-03-01 Natural Gas 3.96300
2022-04-01 Uranium 48.70473
2022-04-01 Natural Gas 4.02100
2022-05-01 Uranium 40.89163
2022-05-01 Natural Gas 4.03100
2022-06-01 Uranium 40.33152
2022-06-01 Natural Gas 4.70200
2022-07-01 Uranium 38.93916
2022-07-01 Natural Gas 4.61900
2022-08-01 Uranium 39.80231
2022-08-01 Natural Gas 4.03400
2022-09-01 Uranium 40.95039
2022-09-01 Natural Gas 3.61700
2022-10-01 Uranium 41.30360
2022-10-01 Natural Gas 3.59200
2022-11-01 Uranium 40.95406
2022-11-01 Natural Gas 3.62800
2022-12-01 Uranium 39.17824
2022-12-01 Natural Gas 3.26000
uranium <- ggplot(df_resources[df_resources$Resources == "Uranium",]) +
                geom_histogram(aes(x = Prices), color = "pink", bins = 30, fill = "darkred") +
                labs(x = "Price", y = "Frequency", title = "Resource Distributions", subtitle = "Uranium") +
                theme_minimal() +
                theme(
                plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
                plot.subtitle = element_text(hjust = 0.5, size = 14),
                axis.title.x = element_text(size = 10),
                axis.title.y = element_text(size = 10),
                plot.margin = margin(1, 1, 1, 1, "cm")
                )

natural_gas <- ggplot(df_resources[df_resources$Resources == "Natural Gas",]) +
                geom_histogram(aes(x = Prices), color = "pink", bins = 30, fill = "darkred") +
                labs(x = "Price", y = "Frequency", subtitle = "Natural Gas") +
                theme_minimal() +
                theme(
                plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
                plot.subtitle = element_text(hjust = 0.5, size = 14),
                axis.title.x = element_text(size = 10),
                axis.title.y = element_text(size = 10),
                plot.margin = margin(1, 1, 1, 1, "cm")
                )

plots <- wrap_plots(uranium, natural_gas, nrow = 2)

plots

library(patchwork)

plot_list <- lapply(unique(df_resources$Resources), function(resource) {
  ggplot(df_resources[df_resources$Resources == resource, ]) +
    geom_histogram(aes(x = Prices), color = "pink", bins = 30, fill = "darkred") +
    labs(x = "Price", y = "Frequency", title = resource) +
    theme_minimal() +
    theme(
      plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
      axis.title.x = element_text(size = 10),
      axis.title.y = element_text(size = 10),
      plot.margin = margin(1, 1, 1, 1, "cm")
    )
})

# Arrange the plots in a grid
grid_plot <- wrap_plots(plotlist = plot_list, nrow = 2)

# Print the grid of histograms
grid_plot

uranium <- ggplot(df_resources[df_resources$Resources == "Uranium",]) +
                geom_boxplot(aes(y = Prices)) +
                labs(x = "", y = "Price", title = "Resource Distributions", subtitle = "Uranium") +
                theme_minimal() +
                theme(
                plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
                plot.subtitle = element_text(hjust = 0.5, size = 14),
                axis.title.x = element_text(size = 10),
                axis.title.y = element_text(size = 10),
                plot.margin = margin(1, 1, 1, 1, "cm")
                )

ggplotly(uranium)
p <- ggplot(df_resources) +
        geom_line(aes(x = DATE, y = Prices), color = "darkred") + 
        labs(x = "Date", y = "Price", title = "Resources Prices") +
        theme_minimal() +
        theme(
                plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
                axis.title.x = element_text(size = 10),
                axis.title.y = element_text(size = 10),
                plot.margin = margin(1, 1, 1, 1, "cm"))+
        facet_grid(Resources ~ ., scales = "free")    

ggplotly(p, width = 800, height = 500)